/**
 * 
 */
package tp.pr5.instructions;

import tp.pr5.NavigationModule;
import tp.pr5.RobotEngine;
import tp.pr5.instructions.exceptions.InstructionExecutionException;
import tp.pr5.instructions.exceptions.WrongInstructionFormatException;
import tp.pr5.items.ItemContainer;

/**
 * Shows the game help with all the instructions that the robot can execute. This instruction works if the user writes HELP or AYUDA
 *
 */
public class HelpInstruction implements Instruction {
	private RobotEngine engine;
	
	/**
	 * It builds a default HelpInstruction
	 */
	public HelpInstruction()
	{}
	

	@Override
	/**
	 * Parses the String returning a HelpInstruction instance or throwing a WrongInstructionFormatException()
	 * @param cad text String to parse
	 * @return Instruction Reference to an instance of HelpInstruction
	 * @throws WrongInstructionFormatException - When the String is not 
	 */
	public Instruction parse(String cad) throws WrongInstructionFormatException {
		if (cad.equalsIgnoreCase("HELP") || cad.equalsIgnoreCase("AYUDA"))
		{
			return new HelpInstruction();
		}
		else
			throw new WrongInstructionFormatException(cad);
	}


	@Override
	/**
	 * Help syntax
	 * @return the instruction syntax HELP
	 */
	public String getHelp() {
		return "HELP|AYUDA";
	}


	@Override
	/**
	 * Configuration of the context for this instruction
	 * @param engine - The robot engine
	 * @param navigation - The information about the game, i.e., the places, current direction and current heading to navigate
	 * @param robotContainer - The inventory of the robot
	 */
	public void configureContext(RobotEngine engine, NavigationModule navigation, ItemContainer robotContainer) {
		this.engine = engine;
	}


	@Override
	/**
	 * Prints the help string of every instruction. It delegates to the Interpreter class.
	 * @thorws InstructionExecutionException - if there exist any execution error.
	 */
	public void execute() throws InstructionExecutionException {
		engine.requestHelp();
	}

}
